package top.littlejiang.onlinexam.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import top.littlejiang.onlinexam.common.base.BasePage;
import top.littlejiang.onlinexam.entity.OlexamSysLog;
import top.littlejiang.onlinexam.mapper.OlexamSysLogMapper;
import top.littlejiang.onlinexam.service.OlexamSysLogService;
import top.littlejiang.onlinexam.common.base.BaseServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统日志 服务实现类
 * </p>
 *
 * @author chen
 * @since 2020-12-26
 */
@Service
public class OlexamSysLogServiceImpl extends BaseServiceImpl<OlexamSysLogMapper, OlexamSysLog> implements OlexamSysLogService {

    /**
     * 分页 列表 查询
     *
     * @param page
     * @return
     */
    @Override
    public IPage<OlexamSysLog> getSyslogListPage(BasePage<OlexamSysLog> page) {
        OlexamSysLog queryParam = page.getQueryParam();
        QueryWrapper<OlexamSysLog> wrapper = new QueryWrapper<>();
        if (!StringUtils.isBlank(queryParam.getUsername())){
            wrapper.like("username", queryParam.getUsername());
        }
        if (page.getPageSize() <= 0){
            page.setPageSize(10);
        }
        Page<OlexamSysLog> p = new Page<>(page.getPageIndex(), page.getPageSize());
        return this.baseMapper.getSyslogList(p, wrapper);
    }
}
